<template>
  <div>
    <p>
    请输入新密码:<input type="text" v-model="newPwd"><br>
    <button @click="submit()" id="btn">确认</button>
    </p>
  </div>
</template>

<script>
import instance from "../../utils/request";

export default {
  name: "UpdatePassword",
  data(){
    return {
      newPwd:'',//新密码
      loginCardNo:''//卡号
    }
  },
  methods:{
    submit(){
      if (this.newPwd == 0 || this.newPwd.length>6){
        alert('密码的长度必须为1~6');
      }else {
        instance.post('/account/updatePassword',{
          "loginCardNo":this.loginCardNo,
          "newPwd":this.newPwd
        }).then(res=>{
          if (res.data > 0){//修改成功
            this.$router.push({name:'Login'});
            alert('密码修改成功!请重新登录')
          }else {
            alert('密码修改失败!');
          }
        });
      }
    }
  },
  created() {
    this.loginCardNo = this.$route.params.cardno;
    if (typeof this.loginCardNo === 'undefined'){//未登录
      this.$router.push({name:'Login'});
    }
  }
}
</script>

<style scoped>
p{
  margin-top: 50px;
  /*黑体*/
  font-family:SimHei;
  /*加粗*/
  font-weight: bold;
}
#btn{
  margin-top: 5px;
}
</style>
